import java.util.Stack;

class MinStack {

    public Stack<Integer> stack;
    public Stack<Integer> minStack;

    public MinStack() {
        stack=new Stack<>();
        minStack=new Stack<>();
    }
    
    public void push(int val) {
        stack.push(val);
        if(minStack.empty()) {
            minStack.push(val);
        }else {
            if(val<=minStack.peek()) {
                minStack.push(val);
            }
        }
    }
    
    public void pop() {
        if(stack.empty())return;
        int ret=stack.pop();
        if(minStack.peek()==ret) {
            minStack.pop();
        }
    }
    
    public int top() {
        if(!stack.empty()) {
            return stack.peek();
        }
        return -1;
    }
    
    public int getMin() {
        if(!minStack.empty()) {
            return minStack.peek();
        }
        return -1;
    }
}